//request请求

const request = class
{
	constructor(url,arg) {
	    this.url=url;
		this.arg=this.baseFun();
	}
	//post 
	modePost()
	{
		
		
		return new Promise((resolve,reject)=>{
			console.log('当前URLS',this.url+"&token="+this.baseFun())
			uni.request({
				url:this.url+"&token="+this.baseFun() ,
				method:"POST",
				data:this.arg,
				header:{Authorization: this.baseFun()
					
				}
			}).then(res=>{
				
				resolve(res[1])
			}).catch(err=>{
				console.log("失败",err)
				reject("出错了")
			})
		}
		
		)
	}
	
	modeGet()
	{
		return new Promise((resolve,reject)=>{
			const token=uni.getStorageSync("token");
			uni.request({
				url:this.url+"&token="+this.baseFun() ,
				method:"GET",
				header:{Authorization: this.baseFun()}
			}).then(res=>{
				resolve(res[1])
			}).catch(err=>{
				reject("出错了")
			})
		}
		
		)
	}
	
	modeLogin()
	{
		return new Promise((resolve,reject)=>{
			
			uni.request({
				url:this.url ,
				method:"GET",
			
			}).then(res=>{
				resolve(res[1])
			}).catch(err=>{
				reject("出错了")
			})
		}
		
		)
	}
	
	//加密token
	baseFun()
	{
		const token=uni.getStorageSync("token");
		
		return  token
	}
}
export default request